1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : suchmaschine/classes/class.spider.inc.php
5 : - Modulgruppe: Suche
6 : - Beschreibung: In dieser Datei wird die Klasse Spider implementiert.
7 : - Version: 1.2 01/17/08
8 : - Autor(en): Torsten Jäger, Gunnar Gillert, Markus Jung, Florian Knöpp
9 : - Autor(en): Joerg Rieger (Refactoring)
10 : +---------------------------------------------------------------------------+
11 : This program is free software; you can redistribute it and/or
12 : modify it under the terms of the GNU General Public License
13 : as published by the Free Software Foundation; either version 2
14 : of the License, or any later version.
15 : +---------------------------------------------------------------------------+
16 : This program is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : GNU General Public License for more details.
20 : You should have received a copy of the GNU General Public License
21 : along with this program; if not, write to the Free Software
22 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 : +--------------------------------------------------------------------------*/
24 : /**
25 : * Path to Root falls nicht gesetzt
26 : */
27 : if (!defined('PATH_TO_ROOT'))
28 : define("PATH_TO_ROOT", "../../");
29 :
30 : /**
31 : * In dieser Datei ist die Klasse Spider implementiert.
32 : *
33 : * @package eStudy.Suchmaschine
34 : * @version 1.2 01/17/08
35 : * @author Torsten Jäger <jaeger.torsten@gmx.net>
36 : * @author Gunnar Gillert
37 : * @author Markus Jung
38 : * @author Florian Knöpp
39 : * @author Jörg Rieger
40 : */
41 :
42 : // Speicherbegrenzung bei Verwendung des Spiders aufheben und Timelimit deaktivieren
43 : ini_set("memory_limit", "-1");
44 : if (!ini_get("safe_mode"))
45 : set_time_limit(0);
46 :
47 : require_once (PATH_TO_ROOT . "common/classes/class.modulautomation.inc.php");
48 :
49 : // Indexer Strategy
50 : require_once (PATH_TO_ROOT . 'suchmaschine/classes/class.iindexer.inc.php');
51 : require_once (PATH_TO_ROOT . 'suchmaschine/classes/class.indexer.inc.php');
52 : require_once (PATH_TO_ROOT . 'suchmaschine/classes/class.indexerstrategy.inc.php');
53 :
54 : // Indexer
55 : require_once (PATH_TO_ROOT . 'suchmaschine/classes/class.pluginvoid.inc.php');
56 : require_once (PATH_TO_ROOT . 'suchmaschine/classes/class.pluginhtm.inc.php');
57 : require_once (PATH_TO_ROOT . 'suchmaschine/classes/class.pluginpdf.inc.php');
58 : require_once (PATH_TO_ROOT . 'suchmaschine/classes/class.pluginzip.inc.php');
59 :
60 :
61 : class Spider extends ModulAutomation {
62 : protected $sc;
63 :
64 : public $translationMatrix;
65 : public $treffer_pro_einzelwort;
66 : public $indexedFiles;
67 : public $stopWords;
68 :
69 : public function Spider() {
70 0 : parent::ModulAutomation();
71 :
72 0 : $this->info = "Suchmaschine";
73 0 : $this->necessaryDatabaseTable = "searchengine_words";
74 :
75 : // Zum Austauschen von UNICode
76 : // in normalen ASCII-Code
77 0 : $this->translationMatrix = array(chr(0) => "", chr(13) => chr(32), chr(10) => chr(32), chr(195) .chr(188) => "ü", chr(195) .chr(182) => "ö", chr(195) .chr(164) => "ä", chr(195) .chr(159) => "ß", chr(195) .chr(156) => "Ü", chr(195) .chr(132) => "Ä", chr(195) .chr(150) => "Ö");
78 0 : $this->treffer_pro_einzelwort = array();
79 0 : }
80 :
81 : /**
82 : * Ist die Hauptroutine der Spider-Klasse und ruft bei
83 : * Bedarf die entsprechenden Funktionen auf.
84 : *
85 : * @access public
86 : * @param string $modus In welchem Modus soll die Funktion laufen
87 : * @param string $datei_id Nur genau diese Datei wird vom Spider indiziert
88 : * @param boolean $output false = keine Status-Ausgabe, true = Status-Ausgabe
89 : */
90 : public function start($modus = "", $fileId = "", $output = false) {
91 0 : global $db, $settings;
92 :
93 : switch($modus) {
94 0 : case '':
95 0 : $this->addToIndex(null, $output);
96 0 : break;
97 0 : case 'add-file':
98 0 : $this->addToIndex($fileId, $output);
99 0 : break;
100 0 : case 'remove-file':
101 0 : $this->removeFilesFromIndex($fileId);
102 0 : break;
103 0 : case 'remove-course':
104 0 : $this->removeFilesFromCourse($fileId);
105 0 : default:
106 0 : $this->addToIndex(null, $output);
107 0 : break;
108 0 : }
109 0 : }
110 :
111 : /**
112 : * Dateien der Suchmaschinen-DB hinzufügen
113 : *
114 : * @access public
115 : * @param int $fileId
116 : * @param boolean $output
117 : */
118 : public function addToIndex( $fileId = '', $output) {
119 0 : global $db, $settings;
120 :
121 0 : $this->sc = new IndexerStrategy();
122 :
123 0 : $fileTypes = $this->sc->getFileTypes();
124 0 : $extensions = $this->makeFileTypeArray($fileTypes);
125 :
126 : // Nur die angegebene Datei indexieren, ansonsten werden alle indexiert
127 0 : if ( $fileId != '' )
128 0 : $queryType = "fileID = '" . Data::toMysql($fileId) . "'";
129 : else
130 0 : $queryType = "type = 'file'";
131 :
132 0 : $sql = "SELECT *
133 : FROM filelist
134 0 : WHERE $queryType
135 0 : AND extension IN ('$extensions')
136 0 : ";
137 0 : $files = $db->get_results($sql, ARRAY_A);
138 :
139 : // Falls keine Einträge gefunden
140 0 : if ( !$db->num_rows )
141 : // throw new Exception ('Keine Dateien zum Indexieren gefunden');
142 0 : return false;
143 :
144 0 : $this->addFilesToDB($files, $fileTypes, $output);
145 0 : }
146 :
147 : /**
148 : * Alle Dateien aus der Suchmaschinen-DB entfernen,
149 : * die dem engegebenen Kurs gehören
150 : *
151 : * @access public
152 : * @param int $fileId
153 : */
154 : public function removeFilesFromCourse( $fileId = '' ) {
155 0 : global $db, $settings;
156 :
157 0 : $delete = "";
158 0 : $dontDelete = "";
159 :
160 : // Übergabeparam. $fileId_param dient hier als KursID
161 0 : $sql = "SELECT word_id FROM searchengine_link ";
162 0 : $sql.= "WHERE course_id = '$fileId'";
163 0 : $delete = $db->get_col($sql);
164 :
165 0 : $sql = "SELECT word_id FROM searchengine_link ";
166 0 : $sql.= "WHERE course_id <> '$fileId'";
167 0 : $dontDelete = $db->get_col($sql);
168 :
169 0 : $sql = "DELETE FROM `searchengine_link` ";
170 0 : $sql.= "WHERE course_id = '$fileId'";
171 0 : $db->query($sql);
172 :
173 0 : $wordIDs = $this->arrayDiff($delete, $dontDelete);
174 :
175 0 : if (!empty($wordIDs))
176 0 : $this->removeFromSearchengineWords($wordIDs);
177 :
178 0 : }
179 :
180 : /**
181 : * Dateien aus der Suchmaschinen-DB entfernen
182 : *
183 : * @access public
184 : * @param int $fileId
185 : */
186 : public function removeFilesFromIndex( $fileId = '' ) {
187 0 : global $db, $settings;
188 :
189 0 : $delete = "";
190 0 : $dontDelete = "";
191 :
192 0 : $sc = new IndexerStrategy();
193 :
194 0 : $fileTypes = $sc->getFileTypes();
195 0 : $extensions = $this->makeFileTypeArray($fileTypes);
196 :
197 0 : if (in_array($db->get_var("SELECT extension FROM filelist WHERE fileID='$fileId'"), $fileTypes)) {
198 0 : $sql = "SELECT word_id FROM searchengine_link ";
199 0 : $sql.= "WHERE file_id='$fileId'";
200 0 : $delete = $db->get_col($sql);
201 :
202 0 : $sql = "SELECT word_id FROM searchengine_link ";
203 0 : $sql.= "WHERE file_id<>'$fileId'";
204 0 : $dontDelete = $db->get_col($sql);
205 :
206 0 : $sql = "DELETE FROM `searchengine_link` ";
207 0 : $sql.= "WHERE file_id='$fileId'";
208 0 : $db->query($sql);
209 0 : }
210 :
211 0 : $wordIDs = $this->arrayDiff($delete, $dontDelete);
212 :
213 0 : if (!empty($wordIDs))
214 0 : $this->removeFromSearchengineWords($wordIDs);
215 0 : }
216 :
217 : /**
218 : * Gibt Erfolg oder Misserfolg der Dateiindizierung aus.
219 : *
220 : * @access public
221 : * @param boolean $output
222 : * @param string $fileOrigName
223 : * @param string $fileId
224 : * @param string $fileLink
225 : * @param int $courseId
226 : * @param string $pluginType
227 : */
228 : public function printStatus($output, $fileOrigName, $fileId, $fileLink, $courseId, $pluginType) {
229 0 : if($output) {
230 0 : if ( $this->isIndexedFile($fileId) )
231 0 : echo("<p style='color:#00A000;'>$pluginType --> <span title='FileId: $fileLink'>" . Data::toHTML($fileOrigName, false) . "</span></p>\n");
232 : else {
233 0 : $courseShort = $this->getCourseShortName($courseId);
234 0 : echo("<p style='color:#A00000;'>$pluginType [$courseShort] --> <span title='FileId: $fileLink'>" . Data::toHTML($fileOrigName, false) . "</span> [nicht indexierbar]</p>\n");
235 : }
236 0 : }
237 0 : }
238 :
239 : /**
240 : * Diese Funktion liefert true zurück, wenn die übergebene Datei noch
241 : * nicht in der Tabelle searchengine_link eingetragen wurde.
242 : *
243 : * @access public
244 : * @param string $fileId ID der zur überprüfenden Datei
245 : * @return boolean
246 : */
247 : public function isIndexedFile( $fileId ) {
248 0 : global $db;
249 :
250 0 : if (!isset($this->indexedFiles)) {
251 0 : $sql = "SELECT DISTINCT file_id FROM searchengine_link";
252 0 : $this->indexedFiles = $db->get_col($sql);
253 :
254 0 : if ($db->num_rows == 0)
255 0 : $this->indexedFiles = array();
256 0 : }
257 :
258 0 : return in_array($fileId, $this->indexedFiles);
259 : }
260 :
261 : /**
262 : * Mit dieser Funktion wird der Link-Name der Datei und das zugehörige
263 : * Suchwort mit Trefferanzahl in der Tabelle: searchengine_link
264 : * eingetragen.
265 : *
266 : * Das Wort und die zugehörige Trefferanzahl stehen in dem Array
267 : * $treffer_pro_einzelwort_array das anschließend wieder gelöscht wird.
268 : *
269 : * @access public
270 : * @param string $fileId Die Link-Bezeichnung der Datei
271 : * @param integer $datei_courseID Welchem Kurs die Datei zugeordnet ist
272 : */
273 : public function createDbLink($fileId, $fileCourseId) {
274 0 : global $db;
275 :
276 : // alle Wörter zum Maskieren durch Data::toMysql() schicken
277 : // der letzte Parameter array() wird an toMysql() übergeben als $isGPCData
278 : // durch die Typfreiheit wird ein leeres Array als false angesehen
279 0 : $words = array_map(array("Data", "toMysql"), array_keys($this->treffer_pro_einzelwort), array());
280 :
281 0 : if (!empty($words)) {
282 0 : $words = $db->get_results("SELECT id, word FROM searchengine_words WHERE word IN ('".implode("', '", $words) ."')");
283 0 : $eingetrageneWoerter = $db->get_col("SELECT word_id FROM searchengine_link WHERE file_id = '$fileId'");
284 0 : $values = "";
285 :
286 0 : foreach($words as $word) {
287 0 : if ((empty($eingetrageneWoerter) || !in_array($word->id, $eingetrageneWoerter)) && isset($this->treffer_pro_einzelwort[$word->word]))
288 0 : $values .= "('$fileId', '$word->id', '$fileCourseId', '{$this->treffer_pro_einzelwort[$word->word]}'), ";
289 0 : }
290 :
291 0 : if (!empty($values)) {
292 0 : $values = substr($values, 0, -2);
293 0 : $sql = "INSERT INTO searchengine_link (file_id, word_id, course_id, hits) ";
294 0 : $sql.= "VALUES $values";
295 0 : $db->query($sql);
296 0 : }
297 :
298 0 : $this->indexedFiles[] = $fileId;
299 0 : }
300 :
301 0 : $this->treffer_pro_einzelwort = array();
302 0 : }
303 :
304 : /**
305 : * Diese Funktion zerlegt den übergebenen String in einzelne Worte
306 : * und trägt Diese in die DB-Tabelle searchengine_words ein.
307 : *
308 : * Dabei werden nur neue Wörter eingetragen, so das keine
309 : * Doppelteinträge vorkommen.
310 : *
311 : * @access public
312 : * @param string $textzeile String der hier noch in einzelne Wörter zerlegt wird
313 : */
314 : public function insertWordsIntoDb($textzeile) {
315 0 : global $db;
316 :
317 0 : $textzeile = $this->cleanString($textzeile);
318 :
319 : // Zerlege den Suchtext in Einzelwörter und
320 : // speichere Sie im Array --> suchtext2
321 0 : $woerter = explode(" ", strtolower($textzeile));
322 :
323 : // Schleife über alle Einzelwörter
324 0 : foreach($woerter as $key => $wort) {
325 0 : if ($this->findWord($wort)) {
326 0 : if (!isset($this->treffer_pro_einzelwort[$wort])) $this->treffer_pro_einzelwort[$wort] = 0;
327 0 : $this->treffer_pro_einzelwort[$wort]++;
328 0 : } else {
329 0 : unset($woerter[$key]);
330 : }
331 0 : }
332 :
333 0 : $woerter = array_unique($woerter);
334 :
335 0 : $eingetragen = $db->get_col("SELECT word FROM searchengine_words WHERE word IN ('".implode("', '", $woerter) ."')");
336 :
337 0 : if (empty($eingetragen))
338 0 : $eingetragen = array();
339 :
340 0 : $einzutragen = array_diff($woerter, $eingetragen);
341 :
342 0 : if (!empty($einzutragen)) {
343 : // alle Wörter zum Maskieren durch Data::toMysql() schicken
344 : // der letzte Parameter array() wird an toMysql() übergeben als $isGPCData
345 : // durch die Typfreiheit wird ein leeres Array als false angesehen
346 0 : $einzutragen = array_map(array("Data", "toMysql"), $einzutragen, array());
347 0 : $sql = "INSERT INTO searchengine_words (word) ";
348 0 : $sql.= "VALUES ('".implode("'), ('", $einzutragen) ."')";
349 0 : $db->query($sql);
350 0 : }
351 0 : }
352 :
353 : /**
354 : * Diese Funktion löscht oder ersetzt unerwünschte Elemente aus dem
355 : * übergebenen String.
356 : *
357 : * z.B. Sonderzeichen und Script-Elemente
358 : *
359 : * @access public
360 : * @param string $textrow zur bearbeitender Ausdruck
361 : */
362 : public function cleanString( $textrow ) {
363 : // Unicode austauschen
364 0 : $textrow = strtr($textrow, $this->translationMatrix);
365 :
366 0 : $search = array('@<script[^>]*?>.*?</script>@si', // JavaScript entfernen
367 0 : '@<[\/\!]*?[^<>]*?>@si', // HTML-Tags entfernen
368 0 : '@([\r\n])[\s]+@', // Leerräume entfernen
369 0 : '@&(quot|#34|amp|#38|lt|#60|gt|#62|nbsp|#160|iexcl|#161|cent|#162|pound|#163|copy|#169);@i', // HTML-Entitäten ersetzen
370 0 : '@[^a-z'.chr(32) .'öäüÖÄÜß]@i'); // Alles außer Buchstaben und Leerzeichen entfernen
371 :
372 0 : $replace = array(' ', ' ', '\1', ' ', ' ');
373 :
374 0 : return preg_replace($search, $replace, $textrow);
375 : }
376 :
377 : /**
378 : * Diese Funktion bestimmt ob es sich bei dem übergebenen
379 : * Ausdruck um ein sinnvolles Wort handelt oder nicht.
380 : *
381 : * Schließlich soll kein Ausdruck der Art z.B.: <sdakfhösd> in die
382 : * DB als Suchwort eingetragen werden.
383 : * Solch sinnlose Ausdrücke kommen aber zwangsläufig beim Einlesen
384 : * von Dateien vor, besonders beim Auslesen von PDF-Dateien.
385 : *
386 : * @access public
387 : * @param string $ausdruck Zu prüfender Ausdruck
388 : * @return boolean Liefert <true> wenn es ein sinnvolles Wort ist
389 : */
390 : public function findWord($ausdruck) {
391 0 : require_once (PATH_TO_ROOT."suchmaschine/classes/stopwords.inc.php");
392 :
393 0 : if (strlen($ausdruck) <= 3 || strlen($ausdruck) > 30 || in_array($ausdruck, $this->stopWords)) {
394 0 : return false;
395 : } else {
396 : // Wenn 2 oder mehr gleiche Buchstaben hintereinander
397 : // kommen, dann kann das kein sinnvolles Wort sein
398 : // (Mit Außnahmen natürlich: Schifffahrt > gültig)
399 0 : $muster = "/(a{3,})|(b{3,})|(c{3,})|(d{3,})|(e{3,})";
400 0 : $muster.= "|(f{4,})|(g{3,})|(h{3,})|(i{3,})|(j{3,})";
401 0 : $muster.= "|(k{3,})|(l{4,})|(m{4,})|(n{3,})|(o{3,})";
402 0 : $muster.= "|(p{3,})|(q{3,})|(r{3,})|(s{4,})|(t{4,})";
403 0 : $muster.= "|(u{3,})|(v{3,})|(w{2,})|(x{2,})|(y{3,})|(z{2,})";
404 0 : $muster.= "|(ä{2,})|(ö{2,})|(ü{2,})|(ß{2,})";
405 : // Wenn 2 gleiche Buchstaben am Anfang des Wortes stehen,
406 : // dann ist es sicherlich kein sinnvolles Wort
407 : // Außnahme (z.B. Aachen -> deswegen bei a 3)
408 0 : $muster.= "|(^a{3,})|(^b{2,})|(^c{2,})|(^d{2,})|(^e{2,})";
409 0 : $muster.= "|(^f{2,})|(^g{2,})|(^h{2,})|(^i{2,})|(^j{2,})";
410 0 : $muster.= "|(^k{2,})|(^l{2,})|(^m{2,})|(^n{2,})|(^o{2,})";
411 0 : $muster.= "|(^p{2,})|(^q{2,})|(^r{2,})|(^s{2,})|(^t{2,})";
412 0 : $muster.= "|(^u{2,})|(^v{2,})|(^w{2,})|(^x{2,})|(^y{2,})|(^z{2,})";
413 0 : $muster.= "|(^ß)|(^ä{2,})|(^ö{2,})|(^ü{2,})";
414 : // Wenn diese Kombinationen vorkommen, dann kann es
415 : // kein sinnvolles Wort (englisch/deutsch) sein!
416 : /*
417 : $muster .= "|(wt)|(gq)|(qf)|(qt)|(qm)|(aä)";
418 : $muster .= "|(pll)|(jv)|(hx)|(öo)";
419 : $muster .= "|(wj)|(cx)|(qx)|(pn)|(qz)|(zx)|(rx)";
420 : $muster .= "|(fv)|(xä)|(äj)|(cn)|(sj)|(üx)";
421 : $muster .= "|(nq)|(cb)|(bq)|(qb)|(zj)|(vx)|(mz)";
422 : $muster .= "|(lq)|(vk)|(afff)|(jp)|(qg)|(yä)";
423 : */
424 0 : $muster.= "|(sxi)|(akd)|(ktx)|(ömq)|(fjk)|(ahh)|(fhh)|(xcü)|(xcß)|(ütc)";
425 0 : $muster.= "|(äüe)|(döe)|(rjz)|(wyy)|(övv)|(nxn)|(nca)|(urwurw)";
426 0 : $muster.= "|(xif)|(xau)|(ztö)|(xzö)|(krß)|(xce)|(xöü)|(fme)|(xüc)";
427 0 : $muster.= "|(xcw)|(äfn)|(xcö)|(xcy)|(fbp)|(xeß)|(mßq)|(cmb)|(csrgb)";
428 0 : $muster.= "|(xox)|(öüc)|(kßk)|(xaw)|(xüä)|(xff)|(nöe)|(qwb)|(xüf)";
429 0 : $muster.= "|(pkp)|(yxr)|(lnä)|(wxo)|(xyx)|(bhj)|(ecd)|(thg)|(öjb)|(öüä)";
430 0 : $muster.= "|(bja)|(fpx)|(dyy)|(jdy)|(hdy)|(pöq)|(pör)|(dfff)|(jje)";
431 0 : $muster.= "|(fpf)|(scc)|(öqü)|(örq)|(iyy)|(cco)|(xüs)|(vyo)|(xcq)|(xmp)";
432 0 : $muster.= "|(xüe)|(xöc)|(xßß)|(xök)|(xöe)|(xüö)|(qsk)|(oön)|(wrb)";
433 0 : $muster.= "|(ooy)|(hgl)|(ühh)|(wßt)|(xmu)|(opß)|(pxa)|(dyx)|(aey)";
434 0 : $muster.= "|(ßho)|(ßpp)|(uöu)|(vyy)|(gii)|(nmn)|(ctx)|(jqö)|(oäa)";
435 0 : $muster.= "|(yyx)|(öäu)|(yqq)|(öän)|(qrr)|(xuu)|(cjc)|(xse)|(aeö)";
436 0 : $muster.= "|(hlß)|(xkw)|(ydd)|(oüc)|(ävö)|(oqn)|(gvw)|(gde)|(aea)";
437 0 : $muster.= "/i";
438 :
439 0 : if (!preg_match($muster, $ausdruck))
440 0 : return true; // sinnvolles Wort gefunden
441 : else
442 0 : return false;
443 : }
444 : }
445 :
446 : /**
447 : * Löschen von indizierten Dateien aus der DB
448 : *
449 : * @access public
450 : * @param int $courseId
451 : * @return bool Erfolgswert
452 : */
453 : public function deleteCourse( $courseId ) {
454 : // $this->start("delete-course", $courseID);
455 :
456 0 : return true;
457 : }
458 :
459 : /**
460 : * Erzeugt ein Array für die SQL Abfrage
461 : *
462 : * @access public
463 : */
464 : public function makeFileTypeArray( $fileTypes ) {
465 0 : $i = 0;
466 :
467 0 : foreach($fileTypes as $key => $val) {
468 0 : $fileArray[$i] = $key;
469 :
470 0 : $i++;
471 0 : }
472 :
473 0 : return implode("', '", $fileArray);
474 : }
475 :
476 : /**
477 : * Erzeugt ein Array für die SQL Abfrage
478 : *
479 : * @access public
480 : * @param array $delete
481 : * @param array $dontDelete
482 : * @return array
483 : */
484 : public function arrayDiff( $delete, $dontDelete ) {
485 0 : $wordIDs = '';
486 :
487 0 : if (isset($delete) && is_array($delete)) {
488 0 : if (isset($dontDelete) && is_array($dontDelete))
489 0 : $wordIDs = array_diff($delete, $dontDelete);
490 : else
491 0 : $wordIDs = $delete;
492 0 : }
493 :
494 0 : return $wordIDs;
495 : }
496 :
497 : /**
498 : * Erzeugt ein Array für die SQL Abfrage
499 : *
500 : * @access public
501 : * @param array $delete
502 : * @return
503 : */
504 : public function removeFromSearchengineWords( $wordIDs) {
505 0 : global $db;
506 :
507 0 : $sql = "DELETE FROM searchengine_words ";
508 0 : $sql.= "WHERE id IN ('".implode("','", $wordIDs) ."')";
509 :
510 0 : $db->query($sql);
511 0 : }
512 :
513 : /**
514 : * Liefert das Kurs-Kürzel
515 : *
516 : * @access public
517 : * @param int $courseId
518 : * @return string
519 : */
520 : public function getCourseShortName( $courseId ) {
521 0 : global $db;
522 :
523 0 : if ( $courseId == 0)
524 0 : return 'Foyer';
525 :
526 0 : $sql = "SELECT ShortName FROM courses WHERE ID = '" . Data::toMysql($courseId) . "'";
527 0 : $course = $db->get_row($sql, ARRAY_A);
528 :
529 0 : return $course['ShortName'];
530 : }
531 :
532 : /**
533 : * Fügt die Dateien in die DB ein
534 : *
535 : * @access public
536 : * @param array $files
537 : * @param array $fileTypes
538 : * @param boolean $output
539 : */
540 : public function addFilesToDb( $files, $fileTypes, $output ) {
541 0 : global $settings, $db;
542 :
543 : // Aufnahme der Daten in die DB
544 0 : foreach($files as $file) {
545 0 : if ( $this->isIndexedFile($file["fileID"]) )
546 0 : continue;
547 :
548 0 : $fileLocation = PATH_TO_ROOT . $settings["upload_path"] . "filemanager/courseID/" . $file["courseID"] . "/" . $file["link"];
549 :
550 : // Anhand der Datei Erweiterung werden die entsprechenden Methoden des zuständigen Plugins aufgerufen
551 : try {
552 0 : $this->sc->usePlugin($fileTypes[strtolower($file['extension'])]);
553 0 : $this->sc->open($fileLocation);
554 0 : $this->insertWordsIntoDb($this->sc->getContent());
555 0 : $this->sc->close();
556 0 : $this->sc->cleanup();
557 : }
558 0 : catch (Exception $e) {
559 :
560 : }
561 :
562 0 : $this->createDbLink($file["fileID"], $file["courseID"]);
563 0 : $this->printStatus($output,
564 0 : $file["orig_filename"],
565 0 : $file["fileID"],
566 0 : $file["link"],
567 0 : $file['courseID'],
568 0 : $this->sc->getPluginName());
569 0 : }
570 0 : }
571 : }
|